﻿// ------------------------------------------------------------------------------------
//      Copyright (c) uhavemyword@gmail.com. All rights reserved.
//      Created by Ben at 2013/2/6 9:46:12
// ------------------------------------------------------------------------------------

namespace CP.NLayer.Client.WpfClient.Modules.Admin
{
    using System;
    using System.Collections.Generic;
    using CP.NLayer.Client.WpfClient.Common;
    using CP.NLayer.Client.WpfClient.Modules.Admin.Role;
    using CP.NLayer.Client.WpfClient.Modules.Admin.User;
    using CP.NLayer.Models.Business;
    using CP.NLayer.Resources.UI;
    using Microsoft.Practices.Prism.Regions;

    public class NavigationViewModel : ViewModelBase
    {
        private IRegionManager _regionManager;
        private CheckListItem _selectedItem;

        public NavigationViewModel(IRegionManager regionManager)
        {
            this._regionManager = regionManager;
            this.Items = new List<CheckListItem>
            {
                new CheckListItem { Text = UiResources.UserManagement, Value = typeof(UserDisplayView) },
                new CheckListItem { Text = UiResources.RoleManagement, Value = typeof(RoleDisplayView) },
            };
        }

        public List<CheckListItem> Items { get; set; }

        public CheckListItem SelectedItem
        {
            get
            {
                return _selectedItem;
            }
            set
            {
                _selectedItem = value;
                if (_selectedItem != null)
                {
                    var viewType = (Type)_selectedItem.Value;
                    this._regionManager.RegisterViewWithRegion(RegionNames.MainContentRegion, viewType);
                    this._regionManager.RequestNavigate(RegionNames.MainContentRegion, viewType.FullName);
                }
                this.RaisePropertyChanged(() => this.SelectedItem);
            }
        }
    }
}
